package com.dlx.activity.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dlx.activity.service.RechargeActivityService;
import com.dlx.common.result.Result;
import com.dlx.model.activity.RechargeActivity;
import com.dlx.vo.activity.RechargeActivityQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author nglon
 * @since 2021-11-17
 */
@RestController
@RequestMapping("/admin/activity/rechargeActivity")
public class RechargeActivityController {

    @Autowired
    private RechargeActivityService rechargeActivityService;

    @PostMapping("{current}/{limit}")
    public Result pageListRechargeActivity(
            @PathVariable Long current,
            @PathVariable Long limit,
            @RequestBody RechargeActivityQueryVo rechargeActivityQueryVo
    ) {
        Page<RechargeActivity> page = this.rechargeActivityService.selectRechargeActivityPage(current, limit, rechargeActivityQueryVo);
        return Result.ok(page);
    }

    @GetMapping("show/{id}")
    public Result show(@PathVariable Long id) {
        RechargeActivity rechargeActivity = this.rechargeActivityService.show(id);
        return Result.ok(rechargeActivity);
    }

    @PostMapping("add")
    public Result add(@RequestBody @Validated RechargeActivity rechargeActivity) {
        Boolean flag = this.rechargeActivityService.add(rechargeActivity);
        return flag ? Result.ok().message("创建成功") : Result.fail().message("创建失败");
    }

    @PostMapping("update")
    public Result update(@RequestBody RechargeActivity rechargeActivity) {
        boolean flag = this.rechargeActivityService.updateRechargeActivity(rechargeActivity);
        return flag ? Result.ok().message("修改成功") : Result.fail().message("修改失败");
    }

    @DeleteMapping("{id}")
    public Result remove(@PathVariable Long id) {
        boolean flag = this.rechargeActivityService.removeById(id);
        return flag ? Result.ok().message("删除成功") : Result.ok().message("删除失败");
    }

    @PostMapping("whetherInActivityTime")
    public RechargeActivity whetherInActivityTime(@RequestBody LocalDateTime currentTime) {
        RechargeActivity rechargeActivity = this.rechargeActivityService.whetherInActivityTime(currentTime);
        return rechargeActivity;
    }

}

